<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>客户端1</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.bootcss.com/ace/1.4.3/ace.js"></script>
    <script src="https://cdn.bootcss.com/ace/1.4.3/ext-language_tools.js"></script>

    <style>
        .mt_4 {
            margin-top: 4px;
        }

        .mt_10 {
            margin-top: 10px;
        }

        #btn_send {
            width: 80px;
        }

        body,
        html {
            width: 1220px;
            margin: 0 auto;
            padding: 0;
            height: 100%;
            overflow: hidden;
        }


        #editor {
            width: 600px;
            height: 600px;
            overflow: hidden;
            line-height: 20px;
        }

        #editor2 {
            width: 600px;
            height: 600px;
            overflow: hidden;
            line-height: 20px;
        }



        .container {
            width: 570px;
            padding: 0;
        }

        .panel-body {
            padding: 0;
            overflow: hidden;
        }


        .panel-default {
            border-color: #272822;
        }


        .request_respone_panel_container {}

        .request_respone_panel_container .panel {
            width: 600px;
        }

        .fl {
            float: left;
        }

        .fr {
            float: right;
        }
    </style>
</head>

<body>



    <div class="request_respone_panel_container">
        <div class="panel panel-default mt_10 fl">
            <div class="panel-heading">请求参数</div>
            <div class="panel-body">
                <div id="content">
                    <div id="editor" class=""></div>
                </div>
            </div>
            <div class="panel-footer">
                <div class="container" id="app">
                    <select v-model="WebToNativeKey" class="form-control">
                        <option v-for="item in SocketServerConfig.WebToNativeKeyArr">{{item}}</option>
                    </select>

                    <button type="button" @click="send" class="btn btn-success btn-block  mt_10">发送</button>

                </div>
            </div>
        </div>

        <div class="panel panel-default mt_10 fr">
            <div class="panel-heading">返回参数</div>
            <div class="panel-body">
                <div id="content">
                    <div id="editor2" class=""></div>
                </div>
            </div>
        </div>
    </div>


    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>

    <script type="text/javascript">


        var editor = ace.edit("editor", {
            theme: "ace/theme/monokai",
            mode: "ace/mode/java",
            autoScrollEditorIntoView: true,
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });
        editor.setShowPrintMargin(false);
        editor.setOption("wrap", "free")

        editor.getSession().on('change', function (e) {
            // e.type, etc
        });

        var editor2 = ace.edit("editor2", {
            theme: "ace/theme/monokai",
            mode: "ace/mode/java",
            autoScrollEditorIntoView: true,
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });
        editor2.setShowPrintMargin(false);
        editor2.setOption("wrap", "free")

        editor2.getSession().on('change', function (e) {
            // e.type, etc
        });

        var SocketServerConfig = {
            url: '172.16.80.156',
            port: '1010',
            WebToNative: {


                KCMP_REGISTER_REQ: {
                    "event": "KCMP_REGISTER_REQ",
                    "server_ip": "172.16.80.156",
                    "local_ip": "10.82.0.15",
                    "conf_id": "1843",
                    "conf_name": "admin2的会议1",
                    "sso_cookie_key": "37969b2d-1e5e-4263-a853-5893adc39714"
                },
                KCMP_SHOW_MONITOR_WINDOW_CMD: {
                    "event": "KCMP_SHOW_MONITOR_WINDOW_CMD"
                },
                DragDrop: // 拖拽时携带的信息
                {
                    "conf_id": "1122334",	  //即会议E164
                    "mt_id": "123.2.12.23.4", //合并mt_id和mcuidx
                    "client_id": 111,		  //客户端id
                    data: {
                        mt: 10
                    }
                },
                KCMP_START_MONITOR_CMD: // 终端音视频流信息
                {
                    "conf_id": "1843",     //即会议E164

                    "mt_id": "123.2.12.23.4", //合并mt_id和mcuidx
                    "alias": "0512110000007",
                    "v_snd_chn": [
                        {
                            "chn_id": 1,
                            "chn_alias": "0512110000007"
                        }
                    ],
                    "a_snd_chn": [
                       
                    ]
                },
                KCMP_UPDATE_STREAM_PARAM_CMD: {  //监控码流信息
                    "event": "KCMP_UPDATE_STREAM_PARAM_CMD",
                    "mode": 0, //0-视频；1-音频；
                    "src": {
                        "encrypt": {
                            "mode": 0,
                            "key": "123456"
                        },
                        "payload_formats": {
                            "real_payload": "96",
                            "active_payload": "106"
                        },
                        "media_formats": {
                            "sampling": 0,  // 音频采样率，仅音频时需要
                            "chn_num": 0,   // 声道数，仅音频时需要
                            "bitrate": 8128,
                            "max_frame": 30 // 帧率，仅视频时需要
                        },
                        "rtcp": {
                            "ip": "127.0.0.1",
                            "port": 6655
                        }
                    },
                    "dst": {
                        "ip": "12.12.12.12",
                        "port": 6615
                    }
                },

                KCMP_STOP_PLAY_CMD: {
                    "event": "KCMP_STOP_PLAY_CMD",
                    "dst": [
                        {
                            "ip": "12.12.12.12",
                            "port": 6615
                        }
                    ]
                },


                KCMP_SHOW_REVIEW_WINDOW_CMD: {  // 开启远遥窗口
                    "event": "KCMP_SHOW_REVIEW_WINDOW_CMD",
                    "client_id":123,
                    "init_position": [100, 700], // 初始位置x, y
                    "extend_x": 0, // 0-向右展开， 1-向左展开
                    "extend_y": 1  // 0-向下展开， 1-向上展开
                },
                KCMP_CLOSE_REVIEW_WINDOW_CMD:
                {
                    "event": "KCMP_CLOSE_REVIEW_WINDOW_CMD"
                },
                KCMP_CHANGE_REVIEW_CMD: {
                    "event": "KCMP_CHANGE_REVIEW_CMD",
                    "mt_id": "12.12.12.4",
                    "alias": "测试终端"
                }
            },
            NativeToWeb: {
                Register_CallBack: {
                    "event": "KCMP_REGISTER_ACK",
                    "version": "5.1.0.1.0"
                },
                KCMP_DRAG_DROP: // 请求监控终端通道信息
                {
                    "event": "KCMP_DRAG_DROP",
                    "conf_id": "1122334",	  //即会议E164
                    "mt_id": "123.2.12.23.4", //合并mt_id和mcuidx
                    "window_id": 1		  	  //窗口id
                },
                KCMP_REVIEW_WINDOW_CLOSE_NTF: {  // 远摇窗口关闭通知
                    "event": "KCMP_REVIEW_WINDOW_CLOSE_NTF"
                }
            }
        };

        SocketServerConfig.WebToNativeKeyArr = [];
        for (key in SocketServerConfig.WebToNative) {
            SocketServerConfig.WebToNativeKeyArr.push(key);
        }

        console.log(SocketServerConfig.WebToNativeKeyArr, "========== SocketServerConfig.WebToNativeKeyArr==========")


        var connString = "ws://" + SocketServerConfig.url + ":" + SocketServerConfig.port;
        console.log(connString, "======connString=========");

        var ws = new WebSocket(connString);

        //连接websocket
        ws.onopen = function () {
            console.log("=========onopen==========");
        };

        //接收消息
        ws.onmessage = function (evt) {
            var innerCodeObj = JSON.parse(evt.data);
            console.log(innerCodeObj, "=========onmessage.innerCodeObj============");
            var innerCode = JSON.stringify(innerCodeObj, null, '\t');
            editor2.session.setValue(innerCode);

        };
        //关闭连接
        ws.onclose = function (evt) {
            console.log("WebSocketClosed!");
        };
        //发生异常
        ws.onerror = function (evt) {
            console.log(evt, "=================WebSocketError!===============");
        };
        var app = new Vue({
            el: '#app',
            data: {
                WebToNativeKey: '',
                SocketServerConfig: SocketServerConfig
            },
            watch: {
                WebToNativeKey: function (newVal, oldVal) {
                    console.log(newVal, "=========newVal=========");
                    console.log(oldVal, "=========oldVal=========");
                    var innerCode = JSON.stringify(this.SocketServerConfig.WebToNative[newVal], null, '\t');
                    editor.session.setValue(innerCode);
                }
            },
            created() {
                this.WebToNativeKey = "KCMP_REGISTER_REQ";
            },
            methods: {
                send() {
                    var json = editor.session.getValue();
                    ws.send(json);
                }
            }
        })

    </script>

</body>

</html>